import {ResultCode} from "@/conf/resultCodeConf";
import {ResultType} from "@/typing/request";


export namespace ResultUtils {
    export function success(result: any): ResultType<any> {
        return {
            success: true,
            err: false,
            data: result,
            code: ResultCode.success,
            message: "success",
            errInfo: null
        }
    }

    export function error(data: any = null, message: any = null, errInfo: any = null): ResultType<any> {
        return {
            success: false,
            err: true,
            data: data,
            code: ResultCode.error,
            message: message,
            errInfo: errInfo,
        }
    }


    export function unknownError(): ResultType<any> {
        return {
            success: false,
            err: true,
            data: null,
            code: ResultCode.error,
            message: 'err',
            errInfo: 'err',
        }
    }

    export function errorCode(code: ResultCode, message: string = 'err'): ResultType<any> {
        return {
            success: false,
            err: true,
            data: null,
            code,
            message,
            errInfo: 'err',
        }
    }




}


